package com.bkhech.picocli;

import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.ExitCodeGenerator;
import org.springframework.stereotype.Component;
import picocli.CommandLine;

import java.util.Arrays;
import java.util.stream.Collectors;

@Component
public class ApplicationRunner implements CommandLineRunner, ExitCodeGenerator {
    private int exitCode;

    @Override
    public void run(String... args) throws Exception {
        System.out.println("---------------");
        Arrays.stream(args).collect(Collectors.joining("|"));
        exitCode = new CommandLine(new ConnectCommand()).execute(args);
    }

    @Override
    public int getExitCode() {
        return exitCode;
    }

}